package com.hut.oa.model.bean;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnore;
/**
 * 用户表
 * 性别字段还没建
 * @author 潘寻毅
 *
 */
@Entity
@Table(name="user_")
public class User {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="u_id")
	private Long id;//用户id
	
	@Column(name="u_name",nullable=false,unique=true)
	private String name;//用户名
	
	@Column(name="u_password",nullable=false)
	private String password;//用户密码
	
	@Column(name="u_real_name",nullable=false)
	private String realName;//用户真实姓名
	
	@Column(name="u_tel",nullable=false)
	private String tel;//用户电话
	
	@Column(name="u_email")
	private String email;//用户邮件
	
	@Column(name="u_address")
	private String address;//用户地址
	
	@Column(name="u_education",nullable=false) 
	private String education;//用户学历
	
	@Column(name="u_graduate_school")
	private String graduationSchool;//毕业院校
	
	@Column(name="u_identity",nullable=false)
	private String identity;//身份证号
	
	@Column(name="u_bank",nullable=false)
	private String bank;//银行卡号

	@Column(name="u_sal",nullable=false)
	private Double sal;//基本工资
	
	@Column(name="u_sex")
	private String sex;//性别
	
	@Temporal(TemporalType.DATE)
	@DateTimeFormat(pattern="yyyy-MM-dd")
	@Column(name="u_bir")
	private Date bir;//生日
	
	@Temporal(TemporalType.DATE)
	@DateTimeFormat(pattern="yyyy-MM-dd")
	@Column(name="u_hiredate",nullable=false)
	private Date hiredate;//入职时间
	
	@Column(name="u_skin")
	private String skin="green";//皮肤
	
	@Column(name="u_status")
	private Integer status=1;//状态
	
	@Column(name="u_photo")
	private String photo;//头像
	
	@JoinColumn(name="u_office_id",nullable=false)
	@ManyToOne
	private DeptOffice deptOffice;//职位
	
	@JoinColumn(name="u_dept_id",nullable=false)
	@ManyToOne(cascade=CascadeType.REFRESH,fetch = FetchType.EAGER)
	private Dept dept;//部门
	
	@ManyToMany(cascade=CascadeType.REFRESH,fetch = FetchType.EAGER)
	@JoinTable(name = "role_user",
	    joinColumns = {
	            @JoinColumn(name = "ru_user_id")
	    }, inverseJoinColumns = {
	    @JoinColumn(name = "ru_role_id")
	})
	private List<Role> roles;
	
	@Transient
	private List<WorkReport> workReport;//所有报告
	
	public User() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getEducation() {
		return education;
	}

	public void setEducation(String education) {
		this.education = education;
	}

	public String getGraduationSchool() {
		return graduationSchool;
	}

	public void setGraduationSchool(String graduationSchool) {
		this.graduationSchool = graduationSchool;
	}

	public String getIdentity() {
		return identity;
	}

	public void setIdentity(String identity) {
		this.identity = identity;
	}

	public String getBank() {
		return bank;
	}

	public void setBank(String bank) {
		this.bank = bank;
	}

	public Double getSal() {
		return sal;
	}

	public void setSal(Double sal) {
		this.sal = sal;
	}

	public Date getBir() {
		return bir;
	}

	public void setBir(Date bir) {
		this.bir = bir;
	}

	public Date getHiredate() {
		return hiredate;
	}

	public void setHiredate(Date hiredate) {
		this.hiredate = hiredate;
	}

	public String getSkin() {
		return skin;
	}

	public void setSkin(String skin) {
		this.skin = skin;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	public String getSex() {
		String sex=null;
		if(this.sex.equals("1")){
			sex="男";
		}else{
			sex="女";
		}
		return sex;	
	}

	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public DeptOffice getDeptOffice() {
		return deptOffice;
	}

	public void setDeptOffice(DeptOffice deptOffice) {
		this.deptOffice = deptOffice;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}
	
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public List<WorkReport> getWorkReport() {
		return workReport;
	}

	public void setWorkReport(List<WorkReport> workReport) {
		this.workReport = workReport;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", name=" + name + ", password=" + password + ", realName=" + realName + ", tel="
				+ tel + ", email=" + email + ", address=" + address + ", education=" + education + ", graduationSchool="
				+ graduationSchool + ", identity=" + identity + ", bank=" + bank + ", sal=" + sal + ", sex=" + sex
				+ ", bir=" + bir + ", hiredate=" + hiredate + ", skin=" + skin + ", status=" + status + ", photo="
				+ photo + "]";
	}
	
}
